Method and system for implementing recovery from speculative forwarding miss-predictions/errors resulting from load store reordering and optimization

ABSTRACT

A method for forwarding data from the store instructions to a corresponding load instruction in an out of order processor. The method includes accessing an incoming sequence of instructions; reordering the instructions in accordance with processor resources for dispatch and execution; ensuring a closest earlier store in machine order for to a corresponding load, by determining if said store has an actual age but said corresponding load does not have an actual age, then said store is earlier than said corresponding load; if said corresponding load has an actual age but said store does not have an actual age, then said corresponding load is earlier than said store; if neither said corresponding load or said store have an actual age, then a virtual identifier table is used to determine which is earlier; and if both said corresponding load and said store have actual ages, then the actual ages are used to determine which is earlier.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of International Application No.PCT/US2013/045730, filed Jun. 13, 2013, which claims the benefit of U.S.Provisional Application No. 61/660,538, filed Jun. 15, 2012a, which arehereby incorporated by reference.

FIELD OF THE INVENTION

The present invention is generally related to digital computer systems,more particularly, to a system and method for selecting instructionscomprising an instruction sequence.

BACKGROUND OF THE INVENTION

Processors are required to handle multiple tasks that are eitherdependent or totally independent. The internal state of such processorsusually consists of registers that might hold different values at eachparticular instant of program execution. At each instant of programexecution, the internal state image is called the architecture state ofthe processor.

When code execution is switched to run another function (e.g., anotherthread, process or program), then the state of the machine/processor hasto be saved so that the new function can utilize the internal registersto build its new state. Once the new function is terminated then itsstate can be discarded and the state of the previous context will berestored and execution resumes. Such a switch process is called acontext switch and usually includes 10's or hundreds of cyclesespecially with modern architectures that employ large number ofregisters (e.g., 64, 128, 256) and/or out of order execution.

In thread-aware hardware architectures, it is normal for the hardware tosupport multiple context states for a limited number ofhardware-supported threads. In this case, the hardware duplicates allarchitecture state elements for each supported thread. This eliminatesthe need for context switch when executing a new thread. However, thisstill has multiple draw backs, namely the area, power and complexity ofduplicating all architecture state elements (i.e., registers) for eachadditional thread supported in hardware. In addition, if the number ofsoftware threads exceeds the number of explicitly supported hardwarethreads, then the context switch must still be performed.

This becomes common as parallelism is needed on a fine granularity basisrequiring a large number of threads. The hardware thread-awarearchitectures with duplicate context-state hardware storage do not helpnon-threaded software code and only reduces the number of contextswitches for software that is threaded. However, those threads areusually constructed for coarse grain parallelism, and result in heavysoftware overhead for initiating and synchronizing, leaving fine grainparallelism, such as function calls and loops parallel execution,without efficient threading initiations/auto generation. Such describedoverheads are accompanied with the difficulty of auto parallelization ofsuch codes using state of the art compiler or user parallelizationtechniques for non-explicitly/easily parallelized/threaded softwarecodes.

SUMMARY OF THE INVENTION

In one embodiment the present invention is implemented as a method forforwarding data from the store instructions to a corresponding loadinstruction in an out of order processor. The method includes accessingan incoming sequence of instructions; reordering the instructions inaccordance with processor resources for dispatch and execution; ensuringa closest earlier store in machine order for to a corresponding load, bydetermining if said store has an actual age but said corresponding loaddoes not have an actual age, then said store is earlier than saidcorresponding load; if said corresponding load has an actual age butsaid store does not have an actual age, then said corresponding load isearlier than said store; if neither said corresponding load or saidstore have an actual age, then a virtual identifier table is used todetermine which is earlier; and if both said corresponding load and saidstore have actual ages, then the actual ages are used to determine whichis earlier.

The foregoing is a summary and thus contains, by necessity,simplifications, generalizations and omissions of detail; consequently,those skilled in the art will appreciate that the summary isillustrative only and is not intended to be in any way limiting. Otheraspects, inventive features, and advantages of the present invention, asdefined solely by the claims, will become apparent in the non-limitingdetailed description set forth below.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention is illustrated by way of example, and not by wayof limitation, in the figures of the accompanying drawings and in whichlike reference numerals refer to similar elements.

FIG. 1 shows a load queue and a store queue in accordance with oneembodiment of the present invention.

FIG. 2 shows a first diagram of load and store instruction splitting inaccordance with one embodiment of the present invention.

FIG. 3 shows a second diagram of load and store instruction splitting inaccordance with one embodiment of the present invention.

FIG. 4 shows a flowchart of the steps of a process where rules forimplementing recovery from speculative forwardingmiss-predictions/errors resulting from load store reordering andoptimization are diagrammed in accordance with one embodiment of thepresent invention.

FIG. 5 shows a diagram illustrating the manner in which the rules ofprocess 300 are implemented with the load queue and store queueresources of a processor in accordance with one embodiment of thepresent invention.

FIG. 6 shows another diagram illustrating the manner in which the rulesof process 300 are implemented with the load queue and store queueresources of a processor in accordance with one embodiment of thepresent invention.

FIG. 7 shows another diagram illustrating the manner in which the rulesof process 300 are implemented with the load queue and store queueresources of a processor in accordance with one embodiment of thepresent invention.

FIG. 8 shows a flowchart of a process of an overview of the dispatchfunctionality where a store is dispatched after a load in accordancewith one embodiment of the present invention.

FIG. 9 shows a flowchart of a process of an overview of the dispatchfunctionality where a load is dispatched after a store in accordancewith one embodiment of the present invention.

FIG. 10 shows a diagram of a unified load queue in accordance with oneembodiment of the present invention.

FIG. 11 shows a unified load queue showing the sliding load dispatchwindow in accordance with one embodiment of the present invention.

FIG. 12 shows a distributed load queue in accordance with one embodimentof the present invention.

FIG. 13 shows a distributed load queue having an in order continuitywindow in accordance with one embodiment of the present invention.

FIG. 14 shows a diagram of a fragmented memory subsystem for a multicoreprocessor in accordance with one embodiment of the present invention.

FIG. 15 shows a diagram of how loads and stores are handled byembodiments of the present invention.

FIG. 16 shows a diagram of a store filtering algorithm in accordancewith one embodiment of the present invention.

FIG. 17 shows a semaphore implementation with out of order loads in amemory consistency model that constitutes loads reading from memory inorder, in accordance with one embodiment of the present invention.

FIG. 18 shows an out of order loads into memory consistency model thatconstitutes loads reading for memory in order by the use of both alock-based model and a transaction-based model in accordance with oneembodiment of the present invention.

FIG. 19 shows a plurality of cores of a multi-core segmented memorysubsystem in accordance with one embodiment of the present invention.

FIG. 20 shows a diagram of asynchronous cores accessing a unified storequeue where stores can afford from either thread based on storeseniority in accordance with one embodiment of the present invention.

FIG. 21 shows a diagram depicting the functionality where stores haveseniority over corresponding stores in other threads in accordance withone embodiment of the present invention.

FIG. 22 shows a non-disambiguated out of order load store queueretirement implementation in accordance with one embodiment of thepresent invention.

FIG. 23 shows a reorder implementation of a non-disambiguated out oforder load store queue reordering implementation in accordance with oneembodiment of the present invention.

FIG. 24 shows an instruction sequence (e.g., trace) reorderedspeculative execution implementation in accordance with one embodimentof the present invention.

FIG. 25 shows a diagram of an exemplary microprocessor pipeline inaccordance with one embodiment of the present invention.

DETAILED DESCRIPTION OF THE INVENTION

Although the present invention has been described in connection with oneembodiment, the invention is not intended to be limited to the specificforms set forth herein. On the contrary, it is intended to cover suchalternatives, modifications, and equivalents as can be reasonablyincluded within the scope of the invention as defined by the appendedclaims.

In the following detailed description, numerous specific details such asspecific method orders, structures, elements, and connections have beenset forth. It is to be understood however that these and other specificdetails need not be utilized to practice embodiments of the presentinvention. In other circumstances, well-known structures, elements, orconnections have been omitted, or have not been described in particulardetail in order to avoid unnecessarily obscuring this description.

References within the specification to “one embodiment” or “anembodiment” are intended to indicate that a particular feature,structure, or characteristic described in connection with the embodimentis included in at least one embodiment of the present invention. Theappearance of the phrase “in one embodiment” in various places withinthe specification are not necessarily all referring to the sameembodiment, nor are separate or alternative embodiments mutuallyexclusive of other embodiments. Moreover, various features are describedwhich may be exhibited by some embodiments and not by others. Similarly,various requirements are described which may be requirements for someembodiments but not other embodiments.

Some portions of the detailed descriptions, which follow, are presentedin terms of procedures, steps, logic blocks, processing, and othersymbolic representations of operations on data bits within a computermemory. These descriptions and representations are the means used bythose skilled in the data processing arts to most effectively convey thesubstance of their work to others skilled in the art. A procedure,computer executed step, logic block, process, etc., is here, andgenerally, conceived to be a self-consistent sequence of steps orinstructions leading to a desired result. The steps are those requiringphysical manipulations of physical quantities. Usually, though notnecessarily, these quantities take the form of electrical or magneticsignals of a computer readable storage medium and are capable of beingstored, transferred, combined, compared, and otherwise manipulated in acomputer system. It has proven convenient at times, principally forreasons of common usage, to refer to these signals as bits, values,elements, symbols, characters, terms, numbers, or the like.

It should be borne in mind, however, that all of these and similar termsare to be associated with the appropriate physical quantities and aremerely convenient labels applied to these quantities. Unlessspecifically stated otherwise as apparent from the followingdiscussions, it is appreciated that throughout the present invention,discussions utilizing terms such as “processing” or “accessing” or“writing” or “storing” or “replicating” or the like, refer to the actionand processes of a computer system, or similar electronic computingdevice that manipulates and transforms data represented as physical(electronic) quantities within the computer system's registers andmemories and other computer readable media into other data similarlyrepresented as physical quantities within the computer system memoriesor registers or other such information storage, transmission or displaydevices.

Embodiments of the present invention implement an out of orderinstruction scheduling process, where instructions within an inputinstruction sequence are allowed to issue, out of order, as soon asprocessor resources are available to execute them. Embodiments of thepresent invention are able to ensure that external agents seeinstructions execute in order (e.g., memory consistency rules/models).Ensuring instructions visibly execute in order to the external agentsthereby ensures error-free program execution. Embodiments of the presentinvention ensure that the memory hierarchy (e.g., L1 cache, L2 cache,system memory, etc.) of the processor sees a consistent in orderexecution of the instructions.

FIG. 1 shows a load queue and a store queue in accordance with oneembodiment of the present invention. FIG. 1 also shows an inputinstruction sequence. As described above, the memory hierarchy (e.g., L1cache, L2 cache, system memory, etc.) of the processor sees a consistentin order execution of the instructions. The load queue and the storequeue, hereafter often referred to as load/store queue, can be used tokeep the semantics of in order execution.

Additionally, out of order execution of the loads and the stores leadsto speculative execution. When performing speculative execution, themachine needs to recognize speculative errors. In the FIG. 1 embodiment,the load/store queue provides a system for implementing recovery fromspeculative forwarding or miss-predictions/errors resulting from loadstore reordering and optimization. The load/store queue comprises thehardware support that allows for recovering from speculative errorsresulting from load store reordering/optimizing as a result offorwarding, branches and faults. To allow the machine to recover fromspeculative errors, the results of the speculative execution aremaintained in the load queue and the store queue. The load queue and thestore queue holds results of the speculative execution until errors canbe corrected and the store results can be retired to memory. Thespeculative execution contents of the load queue and the store queue arenot visible to external agents. With respect to visibility, stores needto be retired to memory in order.

FIG. 2 shows a first diagram of load and store instruction splitting inaccordance with one embodiment of the present invention. One feature ofthe invention is the fact that loads are split into twomacroinstructions, the first does address calculation and fetch into atemporary location (load store queue), and the second is a load of thememory address contents (data) into a register or an ALU destination. Itshould be noted that although the embodiments of the invention aredescribed in the context of splitting load and store instructions intotwo respective macroinstructions and reordering them, the same methodsand systems can be implemented by splitting load and store instructionsinto two respective microinstructions and reordering them within amicrocode context.

The functionality is the same for the stores. Stores are also split intotwo macroinstructions. The first instruction is a store address andfetch, the second instruction is a store of the data at that address.The split of the stores and two instructions follows the same rules asdescribed below for loads.

The split of the loads into two instructions allows a runtime optimizerto schedule the address calculation and fetch instruction much earlierwithin a given instruction sequence. This allows easier recovery frommemory misses by prefetching the data into a temporary buffer that isseparate from the cache hierarchy. The temporary buffer is used in orderto guarantee availability of the pre-fetched data on a one to onecorrespondence between the LA/SA and the LD/SD. The corresponding loaddata instruction can reissue if there is an aliasing with a prior storethat is in the window between the load address and the load data (e.g.,if a forwarding case was detected from a previous store), or if there isany fault problem (e.g., page fault) with the address calculation.Additionally, the split of the loads into two instructions can alsoinclude duplicating information into the two instructions. Suchinformation can be address information, source information, otheradditional identifiers, and the like. This duplication allowsindependent dispatch of LD/SD of the two instructions in absence of theLA/SA.

The load address and fetch instruction can retire from the actualmachine retirement window without waiting on the load data to come back,thereby allowing the machine to make forward progress even in the caseof a cache miss to that address (e.g., the load address referred to atthe beginning of the paragraph). For example, upon a cache miss to thataddress (e.g., address X), the machine could possibly be stalled forhundreds of cycles waiting for the data to be fetched from the memoryhierarchy. By retiring the load address and fetch instruction from theactual machine retirement window without waiting on the load data tocome back, the machine can still make forward progress.

It should be noted that the splitting of instructions enables a keyadvantage of embodiments of the present invention to re-order the LA/SAinstructions earlier and further away from LD/SD the instructionsequence to enable earlier dispatch and execution of the loads and thestores.

FIG. 3 shows a second diagram of load and store instruction splitting inaccordance with one embodiment of the present invention. The FIG. 2embodiment shows how a duplication feature is used in order to enact thesplitting of the load instructions. In this embodiment, the loads areduplicated into two macroinstructions, the first does addresscalculation and fetch into a temporary location (load store queue), andthe second is a load of the memory address contents (data) into aregister or an ALU destination. It should be noted that although theembodiments of the invention are described in the context of duplicatingload and store instructions into two respective macroinstructions andreordering them, the same methods and systems can be implemented byduplicating load and store instructions into two respectivemicroinstructions and reordering them within a microcode context.

A more detailed description of the instruction splitting functionalityin accordance with one embodiment of the present invention is nowdescribed. In one embodiment, the instruction set does not have directanalogue instructions to LA, SA, LD or SD. In such an embodiment, theseconcepts are realized with a combination of instruction prefixes, LAF,SAF, LASAF and a companion suffix instruction. And a set of instructionsthat roughly do map onto the LA has LAD and SA has SAD, and a combinedLADSAD can be implemented. These concepts can also be implemented asmicroinstructions within microcode.

a) What is defined here as LAF-prefix+suffix instruction can bedescribed as an ‘LD’.

b) What is defined here as SAF-prefix+suffix instruction can bedescribed as an ‘SD’.

c) What is defined here as LAD instruction can be described as an ‘LA’.

d) What is defined here as SAD instruction can be described as an ‘SA’.

e) Further we have a LASAF instruction and LADSAD instruction. Theseinstructions comprise a combined LAF/SAF-prefix+suffix instruction whichcould be used to implement semaphore (locked-atomic) operations. It ispossible to also define a combined LAD-SAD instruction to againpre-fetch the memory operands, with resultant complexity in hardware.

LAD stands for ‘LA-defused’

The LAD instruction initiates a data-prefetch into the executionpipeline. It differs from a normal prefetch in that it loads directlyinto the execution pipeline affording lower execution latencies thanfirst level caches. In one embodiment, this functionality is implementedby using a fixed storage for the LA-LD pair that can be tagged using theID link between the LA-LD pair (e.g., the QID number. The LADinstruction calculates an effective memory addresses (e.g., frompotentially a complex specification), specify operand size (byte, halfword, word, double word, or larger); initiate the memory reference;through the TLB and cache hierarchy. Exceptions (page walk miss,privilege, protections,) are recorded to be reported at LAF+suffixexecution OR an alternate implementation could cancel/invalidate the Qentry, forcing the LAF+suffix instruction to re-execute and it to takethe exceptions.

The LAD instruction has the general format and operands:

LAD(os) QID,M[EA]

EA—is the effective address specification, which may be a combination ofbase-register, indexing register, shifting factors and/or indexingoffset. E.g. M[B,RI,sf,offset]

os—is an indication of number of bytes to be read

QID—is the load memory QID to be used for the memory referenceoperation. It is also used to link the LAD's operation and a subsequentLAF-prefixed instruction. The QID is in the range of 1 to N, N is animplementation specific value. Expected values are 31, 63, 127. TheQID=0 is reserved for the special case of LAF instruction which have noantecedent LAD. The QID=0 is always used immediately by the LAF, as suchis not available for a LAD.

LAF stands for ‘LA-fused’.

LAF is an instruction prefix, meaning it must be directly coupled (orfused) with a suffix instruction. The suffix instruction can be standalone. The suffix instruction can be any instruction that has at leastone source register. The LAF as a prefix must be coupled. The LAF-prefixchanges the nature of the suffix instruction. One or more of itsregister operands is redefined by the prefix as a memory queueidentifier (QID). Further the data associated as being sourced from theregister, now is sourced from the memory queue.

A LAF-prefix+suffix instruction may or not have an antecedent LADinstruction. If the QID==0, then the LAF is without an antecedent LAD.If the QID !=0, then the LAF has or had an antecedent LAD. When it isintended to create a split of the load instruction into LA and LD, thenthe LAF will have a QID!=0 and an LAD will be instantiated with the sameQID preceding the LAF (e.g., this basically creates the split LA/LDpair).

When the LAF/suffix executes and has QID==0, the 0 entry of the memoryqueue is used to do an ‘LA’ operation, memory read, stage data into thememory queue, and then completed by loading the data into the suffixinstruction sources and the operation applied combined with potentialother sources and the result written to the suffix instructionsdestination register(s). On the other hand, if the QID!=0, then thememory queue is consulted (lookup) for a matching QID, if present thedata is read from the memory queue and the operation of the suffixinstruction is applied, and result written to the destinations register.If the matching QID is valid but not complete, the data is stalled untildata is available. If the QID is not valid, then the LAF has sufficientenough information (address and data-operand-size) to restart theoperation. A matching QID may not be present for a variety of reasons,some of which are:

a) The antecedent LAD never executed, bad coding, or other reason.

b) the execution flow between LAF and the antecedent LAD was broken byexception or interrupt

c) An intervening store-operations aliased with the LAD's address andinvalidated its data integrity.

In any of these cases, the LAF prefix+suffix have sufficient informationto repeat the LAD (LA) operation. This capability makes our LADinstruction into a hint. The LAD did not have to successfully execute orfor that matter to be even be implemented beyond being a NOP for correctcode to use it.

The general format and operands of a LAF instruction with a suffixinstruction is:

LAF M[ea]

SUFFIX(os) Rt,QID, . . . .

The LAF instruction borrows is operand size, QID, and from the encodingof the suffix instruction. If the suffix is a SIMD, it also borrows fromthe suffix the SIMD-width of the operation. The QID is always encoded inone of the source register specification fields of the suffixinstruction. In SMI's particular implementation this is always bits23:18, but this does not need to be the case.

SAD stands for ‘SA-defused’

SAD is the parallel instruction to a LAD only for stores. It tooprefetches data bringing in data to caches for modification. Further itcreates a memory-store-queue entry. SAD primary has 2 primary uses:

a) as a prefetch, read for modification of data

b) to keep correct memory ordering and expose and handle potentialwrite-after-read hazards after promoting a load (read) before a store(write)

SAD is a hint instruction. The SAD instruction calculates an effectivememory address (from potentially a complex specification), specifiesoperand size (byte, half word, word, double word, . . . ); initiatesmemory reference; through TLB, cache/memory hierarchy. Exceptions (pagewalk miss), privilege, protection) are recorded at SAF+suffix executionto re-execute and it to take the exceptions.

The SAD instruction has the general format and operands:

SAD(os) M[ea],QID

Ea—is the effective address specification, which may be a combination ofbase-register, indexing register, shifting factors and/or indexingoffset. E.g. M[B,RI,sf,offset]

Os—is an indication of number of bytes to be written to the Ea

QID—is the store memory QID to be used for the memory referenceoperation. It is also used to link the SAD's operation and an subsequentSAF prefixed instruction. The QID is in the range of 1 to N, N is animplementation specific value. Expected values are 31, 63, 127. TheQID=0 is reserved for the special case of SAF instruction which have noantecedent SAD. This QID is always used immediately by the SAF.

SAF stands for ‘SA-fused’

SAF is the parallel prefix to the LAF prefix, only for stores. As aprefix it must be directly coupled (or fused) with a suffix instruction.The suffix instruction can be stand alone. The suffix instruction can beany instruction that has at least one target register. The SAF as aprefix must be coupled. The SAF changes the nature of the suffixinstruction: one or more of the destination register operands which isnormally register-selection index into a memory store queue identifier(QID), and the operation from targeting a register to targeting a memory(more precisely a memory queue entry). As such it changes a registeroperation into a store memory operation.

The SAF instruction may or may not have an antecedent SAD. If theQID==0, then the SAF is without an antecedent SAD. If the QID !=0, thenthe SAF has or had an antecedent SAD. When the SAF/suffix executes ifthe QID==0, the 0 entry of the memory queue is used to do an ‘SA’operation, memory write, stage data into the memory queue, and thencompleted by storing the data supplied by the suffix instruction source.On the other hand, if the QID!=0, then the memory queue is consulted(lookup) for a matching QID, if present the data will be written intothe memory queue entry when the operation of the suffix instruction isapplied. If the matching QID, is valid but not complete, the data isstalled until data is available. If the QID is not valid, then the SAFhas sufficient enough information (address and data-operand-size) torestart the operation and complete the memory write operation. Amatching QID may not be present for a variety of reasons, some of whichare:

a) the antecedent SAD never executed, bad coding, or other reason.

b) the execution flow between SAF and the antecedent SAD was broken byexception or interrupt

In any of these cases, the SAF prefix+suffix have sufficient informationto repeat the SAD (SA) operation. This capability makes our SADinstruction into a hint. The SAD did not have to successfully execute orfor that matter to be even be implemented beyond being a NOP for correctcode to use it.

LASAF is an instruction prefix

LASAF as a prefix modifies an instruction that has a same register as asource and a destination. LASAF changes such an instruction into anatomic memory reference read/write once operation. One from theload-memory queue and one from the store memory queue are used. There isno antecedent LAD or SAD instruction.

LASAF M[ea3]

ADD QID1,QID2,R1

LASAF creates QID entries in both the load and store memory queue. Andwould them read memory[ea3] using QID2, add R1 and store the result instore memory QID1, effectuating an atomic read-modify write of M[ea3].

The SMI implementation (if we were to implement this) would requireQID1==QID2==0. But we don't want to restrict ourselves to thatimplementation.

Could we have a LASAD instruction, I think so, but we′d have to snoopall the way into the memory queue's to do it. Invalidate both entries ona snoop on a hit. And then re-execute the load/store on the LASAF.

Example usage:

A. Saving Register Resource after Promoting a Load Far in Advance of aUse of the Data.

Assume the original code is.

LDR R1,M[ea1]

ADD32 Rt,R1,R2

To hide memory access latency we wish to promote in execution flow theLDR as early as possible above the usage of the R1 data (the ADD).

LDR R1,M[ea1]

many instructions

ADD32 Rt,R1,R2

One downside of doing this is it keeps the R1 register ‘busy’ waitingfor data, and it can not be used for other purposes. The memory queueexpands the pool of resources to hold data. So we covert the in LDR intoa LAD and a subsequent LAD:

LAD QID,M[ea1]

. . . many instructions

LAF M[ea1]

ADD32 Rt,QID,R2

Since a load-queue entry QID is used R1, is freed to be used for otherpurposes.

Or load Rt with the difference of Rt-QID, or if QID not present thenreload data from M[ea1] subtract R2 from it, and place result in Rt.

It should be noted that with the above described implementation it isnot necessary for the memory address calculation to match between the 2loads. If the two address calculations differ, and the QID is stillvalid there is most likely a bad programmer. The OS (in our example 32),also does not have to match between the LAD and LAF. More data thannecessary may be read by the LAD, in which case the least-significantbytes of the data read will be used. Or more data may be required by theLAF+suffix than the LAD read, in which case the least-significant bytesread by the LAD will be used, followed by 0 until the suffix operationis sufficed. Further the address calculation operands do not have tomatch between the LAD and LAF, although for good coding they should getthe same resultant effective address.

B. Saving Execution Cycles, by Morphing a Normal ALU Register-RegisterOperation into an ALU Register Memory Operation.

Here we are using the special QID=0 (%0) just to change the normalregister-register ADD instruction into a memory reference. Since LAF isa prefix and must be directly coupled to the ADD, there is noinstruction in between. The QID=0 is always available for usage, as itis immediately used.

LAF M[ea1]

ADD32 Rt,% q0,R2

LAF effectively changes the above instruction into

ADD32 Rt,M[ea1],R2

We can also use SAF to morph an ALU register-register operation into aoperation that stores the result of the ALU operation into memory.

SAF M[ea1]

ADD % q0,R2,R3

Will store the result of adding R2 and R3 into memory at address ea1.

C. Preserving Order Semantic when Promoting Load Above Stores.

Another issue is that we want to promote the load (LDR) above a store(STR) which may or may not alias with the address of the load. Alias:some or all of the data address by ea1 is the same as ea2.

STR M[ea2]

LDR R1,M[ea1]

ADD32 Rt,R1,R2

becomes

LDR R1,M[ea1]

0-to-many instructions

STR M[ea2],R3

0-to-many instructions

ADD32 Rt,R1,R2

To safely do this safely (generate correct code), we need the tools todo it. Here we use both LAD and SAD instructions and their respectiveLAF and SAF prefix+suffix instructions, and to be able to preserveexecution order and generate correct code.

LOOP:

SAD M[ea2],R3

0-to-many instructions

a)

LAD R1,M[ea1]

0-to-many instructions

b)

SAF M[ea1],R3

0-to-many instructions

c)

saf-suffix

LAF M[ea1]

d)

BRN LOOP

In the above code both the LAD and the SAD have to be promoted and keepthe same ordering. What can happen? At each point a, b, c, d analternate is indicated.

a1) interrupt, invalidates the SAD, the subsequent SAF will have tore-execute

a2) LAD aliases with SAD, invalidates the LAD or rather wont be insertedinto the memory queue

b1) interrupt, invalidated the SAD and LAD

b2) SAF aliases with the LAD, and invalidates the LAD

b3) SAF either uses the still valid SAD, or re-executes.

c1) interrupt, invalidates the LAD,

c2) if still valid LAF uses LAD's data, otherwise re-executes.

c3) loops, do to the magic of hardware, a combination of tagging with IPand execution sequence ID, and the QID, LAD/SAD/LAF/SAF are properlymanaged.

In the above described descriptions of LA/SA and LD/SD, the LA and SArelative program order positions are used to enforce order forforwarding purposes. In another embodiment, the LD/SD relative programorder positions can be used to enforce order for forwarding purposes(e.g., as described below).

FIG. 4 shows a flowchart of the steps of a process 400 where rules forimplementing recovery from speculative forwardingmiss-predictions/errors resulting from load store reordering andoptimization are diagrammed in accordance with one embodiment of thepresent invention.

As illustrated by step 401, an objective of embodiment of the presentinvention as to find stores that forward to a load upon an address matchbetween that store and that load. In step 402, the closest earlier store(e.g., in machine order) forwards to the load.

In step 403, the actual ages are updated for LA/SA when LD/SD isallocated in machine order. The LA/SA actual ages are assigned the samevalue as the LD/SD ages. The LD/SD maintains the actual ages andenforces the original program order semantics.

Steps 404-407 show the rules for maintaining program sequentialsemantics while supporting speculative execution. The steps 404-407 areshown as being arranged horizontally with each other to indicate thatthe mechanisms that implement these rules function simultaneously. Asshown in step 404, if a store has an actual age but the load has not yetobtained an actual age, then the store is earlier than the load. Asshown in step 405, if a load has an actual age but the store has not yetobtained an actual age, then the load is earlier than the store. Asshown in step 406, if either the load or the store has obtained anactual age, then a virtual identifier (VID) will be used to find outwhich is earlier (e.g., in some embodiments the QID that is associatedwith the load/store instructions represents the VID). As shown in step407, if both a load and a store have obtained actual ages, then theactual age is used to find out which is the earlier.

It should be noted that algorithm described by the FIG. 4 embodimentused to determine the relative age between a load and a store can alsobe used to determine the relative age among a plurality of stores. Thisis useful in updating the store age stamp as described below in FIG. 4and subsequent figures.

FIG. 5 shows a diagram illustrating the manner in which the rules ofprocess 400 are implemented with the load queue and store queueresources of a processor in accordance with one embodiment of thepresent invention. The FIG. 5 embodiment shows an example where a loopof instructions has been unrolled into two identical instructionsequences 401-402. It should be noted that the SA and LA can be freelyreordered, however, the SD and LD have to maintain their relativeprogram order. Earlier stores can forward to later loads. Earlier meanssmaller VID (e.g., as maintained in the virtual ID table) or smallerage. If an SA has a VID but no age that SA is later than a load that hasan age. Actual age of LA/SA gets updated at the allocation of LD/SD andassigned the same age of the LD/SD. If a store or a load has an actualage, it compares with the actual age, else VID age is used.

It should be noted that the VID table functions by keeping track of theassociations between the LA/SA and LD/SD instructions by storing theLA/SA corresponding machine ID and machine resources that correspond toeach VID unique identifier. It should also be noted that the term “VID”is synonymous with the term “QID” as described in the discussion of FIG.2A and FIG. 2B.

An example of operation of the FIG. 4 embodiment is now described.Initially, consider a case where the allocation pointer 410 wasinitially at 3. V3 LA has been dispatched and allocated in the load Qentry #4. Both V1 SA and V2 SA have been dispatched. They compare withV3 LA and because V2 SA is smaller than V3 LA and closer to it than V1SA, then it is potentially forwarding to V3 LA, and thus it updates thestore initial age for the V3 LA load Q entry.

The allocation pointer now moves to 6. The store actual age of V2 SA(#5) now updates the V3 LA load Q entry (because V2 SA is the store ofrecord that has stamped to forward to this load). V4 SA now dispatchesand compares with the load initial age, and because V4 is larger than V3LA, it does not forward. Allocation pointer now moves to 11. At the timeof allocation of V3 LD, it updates the load Q entry #4 with the actualage of V3 LD (#7). V1 SA #11 is now dispatched. Since V3 LA #1 now hasan actual age but not V1 SA #11, then the load is earlier than thestore, and thus no forwarding is possible.

The prediction table is for detecting cases where the default assumptionhas been incorrect. The default assumption is that no store forwards toa load. Once forwarding is detected for a load store pair the programcounter of the load store pair is recorded so that the load will alwayswait for that store address to be dispatched and address calculated tofind out if that load address matches that store address and thus needsto forward from it.

It should be noted that in one embodiment, the feature described herein,wherein the LD/SD is allowed to dispatch in absence of the LA/SA,facilitates reordering of LA/SA ahead of a branch or within a branchscope in a given sequence of instructions. If the LA and SA were skippedover as a result of a branch, or they were ignored as a result of havingcaused a memory exception, the LD and SD can still function correctlybecause they include the necessary information to dispatch twice: firstas an LA/SA, and second as an LD/SD. In such case, the first dispatch ofthe LD/SD is performing the address calculation (e.g., load address).Subsequently, the same LD/SD can dispatch again to fulfill the consumingpart of the load or store (e.g., load data). This mechanism can bereferred to as a “dual dispatch” of the load and store instructions.

It should be noted that, in one embodiment, the dual dispatch of theLD/SD happens when the corresponding defused LA/SA is non-existent(e.g., as is the case with a fused LD/SD), or if the LA/SA was skippedover as a result of a branch, or they were ignored as a result of havingcaused a memory exception, or the like.

The above described dual dispatch functionality ensures LD/SD executescorrectly independent of the lost, ignored or skipped LA/SA. The benefitprovided by the above described feature is that prefetching of the dataspecified by the load/store can start earlier in the program order(e.g., reducing latency) by scheduling the LA/SA earlier, even in thepresence of branches, potential faults, exceptions, or the like.

FIG. 6 shows another diagram illustrating the manner in which the rulesof process 400 are implemented with the load queue and store queueresources of a processor in accordance with one embodiment of thepresent invention. In the FIG. 6 embodiment, consider a case where theallocation pointer was initially at 3. V3 LA has been dispatched andallocated in the load Q entry #4. The allocation pointer now moves to 6.The store actual age of V1 and V2 (#4, #5) now updates the correspondingSA's with machine ID 2 and 3. V4 SA now dispatches and compares with theload initial age, and because V4 SA is larger than V3 LA, it does notforward. The allocation pointer now moves to 11. At the time ofallocation of V3 LD, it updates the load Q entry #4 with the actual ageof V3 LD (#7). Now V1 LA of ID 10 is now dispatched.

Both V1 SA of machine ID 2 and V2 SA of machine ID 3 are now dispatched.They compare with V1 LA of ID 10 and because V1 LA of ID 10 has nomachine age (its corresponding LD has not been allocated yet), whileboth V1 SA of machine ID 2 and V2 SA of machine ID 3 have actual age,then it is known that both V1 and V2 stores are earlier/older than V1.Then the latest of these two stores (V2) can forward to V1 of ID 10. SA(V2) #11 is now dispatched. Since V1 LA and V2 SA do not have an actualage, their VID's are used for comparison, and no forwarding is detected.The allocation pointer now moves to 16. V4 SA of ID 16 is now dispatchedand it compares with V1 LA of ID 10 and since the V1 LA has an actualage but the V4 SA does not, then the V4 SA is later than the V1 LA. Thusno forwarding from this store to this earlier load is possible.

FIG. 7 shows another diagram illustrating the manner in which the rulesof process 400 are implemented with the load queue and store queueresources of a processor in accordance with one embodiment of thepresent invention. In Figure the 7 embodiment, consider a case where theallocation pointer was initially at 3. V1 SA and V2 SA have beendispatched and allocated in the store Q entry #4 and #5. The allocationpointer now moves to 6 and V4 SA is dispatched. Both V1 SA and V2 SA gettheir actual age of 4 and 5.

The allocation pointer now moves to 11. V3 LA gets the actual age of 7.V1 SA #10 V2 SA #11 are dispatched. V3 LA is dispatched and it comparesits address with the store Q entries and finds a match across V1 SA, V2SA and V4 SA and V2 SA #11. Since V3 LA has its actual age of 7, itcompares its actual age with the closest store age to it, which is age5, belonging to V2 SA, and thus that load will forward from this storeand be marked such in the load Q.

FIG. 8 shows a flowchart of a process 800 of an overview of the dispatchfunctionality where a store is dispatched after a load in accordancewith one embodiment of the present invention.

Process 800 begins in step 801, where a store instruction is split intoan SA and SD. As described earlier, the SA instruction maintainssemantics with the SD instruction to allow dual dispatch in the eventthat there is no match in the VID table between the split SA and thejust allocated SD. In step 802, SA is reordered to an earlier machinevisible program order and that SA is tracked using a VID table to retainthe original SD program order. In step 803, upon dispatch of the SA, acheck is made against all loads in the load queue for address matchagainst the SA.

In step 804, upon an address match, the program order of the matchingloads is compared against the program order of the SA by using the VIDnumbers of the loads and the SA, or using the actual ages of the loadsand the stores. This is the process that was diagrammed earlier in thediscussion of the FIG. 3. If a store has an actual age but not load thenthe store is earlier than the load. If a load has an actual age but notthe store then the load is earlier than the store. If either a load or astore has an actual age, then a virtual identifier (VID) can be used tofind out which is earlier. If both a load and a store have actual agesthen the actual age is used to find out which is the earlier. Asdescribed above, the VID number allows the tracking of original programorder and the reordered SA and LA. The entries in the VID table allowsthe corresponding SD and LD to get associated with the machine resourcesthat were assigned to the SA and LA when they were allocated.

In step 805, for loads that are later in the program order, the storewill check to see if the loads have been forwarded to by other stores.In step 806, if so, the store checks a stamp of the store thatpreviously forwarded to this load to see if that store was earlier inprogram order than itself. In step 807, if so, the store checks a stampof the store that previously forwarded to this load to see if that storewas earlier in program order than itself. In step 808, if not, the storedoes not forward to this load.

FIG. 9 shows a flowchart of a process 900 of an overview of the dispatchfunctionality where a load is dispatched after a store in accordancewith one embodiment of the present invention.

In step 901, a load instruction is split into an LA and LD in the mannerdescribed above. In step 902, the LA is reordered to an earlier machinevisible program order and is tracked using the VID table as describedabove. Instead 903, the LA is checked against all stores in the storequeue for address match against the load.

In 904, upon an address match, compare the program order of the matchingload against the program order of the store by using the VID numbers ofthe load and the store, or using the actual ages of the load and thestore. This is the process that was diagrammed earlier in the discussionof the FIG. 3. If a store has an actual age but not load then the storeis earlier than the load. If a load has an actual age but not the storethen the load is earlier than the store. If either a load or a store hasan actual age, then a virtual identifier (VID) can be used to find outwhich is earlier. If both a load and a store have actual ages then theactual age is used to find out which is the earlier. As described above,the VID number allows the tracking of original program order and thereordered SA and LA. Subsequently, in step 905, the load consumes thedata from the store that is closest in program order to its own programorder.

FIG. 10 shows a diagram of a unified load queue in accordance with oneembodiment of the present invention. An objective of a virtualload/store queue is to allow the processor to allocate in the machinemore loads/stores than can be accommodated using the actual physicalsize of its load/store queue. In return, this allows the processor toallocate other instructions besides loads/stores beyond the processor'sphysical size limitation of its' load/store queue. These otherinstructions can still be dispatched and executed even if some of theloads/stores still do not have spaces in the load/store queues.

As loads retire out of the load queue, the load dispatch window moves tosubsequent instructions in the sequence and will include more allocatedloads to be considered for dispatch equivalent to the number of loadsthat have retired from the load queue. In this diagram, the loaddispatch window will move from left to right.

In one embodiment, the load dispatch window will always include thenumber of loads that equal the number of entries in the load queue. Noloads at any time can be dispatched outside the load dispatch window.Other instructions in the scheduler window besides loads (e.g., Sub, Addetc.) can dispatch. All loads within the load dispatch window candispatch whenever they are ready.

FIG. 11 shows a unified load queue showing the sliding load dispatchwindow in accordance with one embodiment of the present invention. FIG.11 shows a subsequent instance in time in comparison to FIG. 10. Asloads retire out of the load queue, the load dispatch window moves tosubsequent instructions in the sequence and will include more allocatedloads to be considered for dispatch equivalent to the number of loadsthat have retired from the load queue. The load dispatch window willalways include the number of loads that equal the number of entries inthe load queue. No loads at any time can be dispatched outside the loaddispatch window. Other instructions in the scheduler window besidesloads (e.g., Sub, Add etc.) can dispatch. All loads within the loaddispatch window can dispatch whenever they are ready. Thus, one benefitobtained by this scheme is that allocating into the scheduler is notstalled if the load or the store queues capacity is exceeded, instead wecontinue allocating instructions intro scheduler including loads andstores in spite of the load or store queue capacity being exceeded, theload and store dynamic windows will insure no load or store outside thecapacity of the load or store queue will be dispatched.

FIG. 12 shows a distributed load queue in accordance with one embodimentof the present invention. An objective of the FIG. 12 embodiment is toimplement a distributed load queue and a distributed store queue thatmaintains single program/thread sequential semantics but still allowsthe out of order dispatch of loads and stores across multiplecores/memory fragments.

The FIG. 12 diagram shows a load queue extension solution to avoiddeadlocks. An extension of the load/store queue is created and is usedto allocate deadlocked loads/stores to that extension queue in programorder from the point of the load/store that caused the deadlock (fromthat point onward) until the load/store queue has free entriesavailable. In the FIG. 12 scenario, the LD 3 load depends on SD which inreturn depends on LD 2 (having an address that maps to load_Q B) whichcannot be dispatched because the load_Q B is full. In this deadlockscenario, upon detection of the deadlock, LD 1 and LD 2 are allowed todispatch and retire in order one after the other into the reserveportion B. A conservative policy for a distributed load/store queue isto reserve for each load/store an entry in each load/store distributedqueue. In this Figure, each allocated load needs to reserve an entry inload_Q A and another entry in load_Q B.

It should be noted that in distributed load/store queues, there is aproblem with respect to allocated load/stores in that their address isunknown at allocation time. Because of this, it is only known at out oforder dispatch time which of the distributed queues a given load orstore will occupy.

Embodiments of the present invention can employ three differentsolutions for the distributed load/store queue to avoid deadlocks without of order dispatches:

1. Cause a miss-prediction and flush at the earliest load/store thatdeadlocked (have no space to dispatch to the load/store buffer) andstart dispatching load/stores either in order for a period of time, orby conservative allocation where each load/store allocates space in alldistributed queues. Once the address of that load/store is known (atdispatch time) thus the particular load queue which will receive thatload/store is known, it can de-allocate the reserved spaces in the otherqueues.2. An extension of the load/store queue is created and is used toallocate deadlocked loads/stores to that extension queue in programorder from the point of the load/store that caused the deadlock (FIG.9).3. Dynamic dispatch window sizing, where the sum of the un-dispatchedloads outside the continuity window should be less than or equal to thenumber of free unreserved spaces in that particular load queue (e.g.,FIG. 11).

FIG. 13 shows a distributed load queue having an in order continuitywindow in accordance with one embodiment of the present invention.Dynamic load dispatch window sizing is determined such that the sum ofthe un-dispatched loads outside the continuity window should be lessthan or equal to the number of free unreserved spaces in that particularload queue. Each load queue will track its entries using its respectivedispatch window as shown here. The dynamic window size for each loadqueue at any time=physical size of that queue plus the virtual entries(in this case 6+4=10) thus in this case, the window size should onlycover 10 loads. Note loads for other queues are not counted (e.g., LD4).

Booking ratio of the reserve is 3. The booking ratio is the number of inorder loads that compete for each of the reserved spaces. In thisexample, only the first two in order un-dispatched loads (scanning thein-order continuity window from the left to right) can dispatch to thereserve portion (assuming 2 entries of the queue were assigned toreserve). Hence, the number of virtual entries=(Booking ratio−1)*numberof reserve entries=(3−1)*2=4.

With respect to the in order continuity window sizing, the number ofloads at any time (counting from the oldest to the youngest) that havenot dispatched to an entry (captured space) in the load queues plus thenumber of dispatched loads to the reserve space must be less than orequal to (the booking ratio*the number of reserve entries). In thiscase, the number of loads must be less than or equal to 3. The bookingratio is a design configurable performance metric that determines whatis the accepted (occupancy VS booking) ratio of the reserved space. Thisis exercised in case the earliest un-dispatched loads cannot find aqueue space to dispatch to outside the reserved entries. In such case,those loads starting from the earliest (oldest) load will compete forthe reserved space, the booking ratio determines how many loads willwait to occupy each reserved entry, the reserved entries are alwaysassigned first to the oldest un-dispatched load and once that loadretires the next oldest load can occupy the entry (the booking ratiodetermines the number of those loads that occupy the reserved entriesone after the other starting from the oldest dispatched).

It should be noted that in one embodiment, loads from the in ordercontinuity window of each queue can dispatch to the reserved space ofthat queue when there is no space left in the unreserved portion of thatqueue (starting from the oldest load in order). It should be also notedthat in one embodiment, loads outside the in order continuity window ofeither queue and within the dynamic dispatch window of that queue cannotdispatch to the reserved portion of that queue.

It should be noted also that as long as there is space in the unreservedportion of the queue, any load within the whole dynamic dispatch windowof that queue can dispatch out of order to any entry of the unreservedportion of any of the distributed queues. The sizes of both the in ordercontinuity window and the dynamic dispatch window of either queue isadjusted each cycle to reflect their size limitations stated in theequations provided above after each load dispatch or retirement.

FIG. 14 shows a diagram of a fragmented memory subsystem for a multicoreprocessor in accordance with one embodiment of the present invention.FIG. 13 shows a comprehensive scheme and implementation of thesynchronization scheme among threads and/or among loads and stores ingeneral. The scheme describes a preferred method for synchronization anddisambiguation of memory references across load/store architecturesand/or across memory references and/or threads' memory accesses. In FIG.15, multiple segments of register files (address and or data registers)are shown, along with execution units, address calculation units, andfragment s of level 1 caches and/or load store buffers and level 2caches and address register interconnects 1200 and address calculationunit interconnects 1201. Those fragmented elements could be constructedwithin one core/processor by fragmenting and distributing itscentralized resources into several engines or they can be constructedfrom elements of different cores/processors inmulti-core/multi-processor configurations. One of those fragments 1211is shown in the figure as fragment number 1; the fragments can be scaledto a large number (in general to N fragments as shown in the figure).

This mechanism also serves also as a coherency scheme for the memoryarchitecture among those engines/cores/processors. This scheme starts byan address request from one of the address calculation units in onefragment/core/processor. For example, assume the address is requested byfragment 1 (e.g., 1211). It can obtain and calculate its address usingaddress registers that belong to its own fragment and or from registersacross other fragments using the address interconnect bus 1200. Aftercalculating the address it creates the reference address of either32-bit address or 64-bit address that is used to access caches andmemory. This address is usually fragmented into a tag field and a setand line fields. This particular fragment/engine/core will store theaddress into its load store buffer and/or L1 and/or L2 address arrays1202, at the same time it will create a compressed version of the tag(with smaller number of bits than the original tag field of the address)by using a compression technique.

Moreover, the different fragments/engines/cores/processors will use theset field or a subset of the set field as an index to identify whichfragment/core/processor the address is maintained in. This indexing ofthe fragments by the address set field bits ensures exclusiveness ofownership of the address in a particular fragment/core/engine eventhough the memory data that corresponds to that address can live inanother or multiple other fragments/engines/cores/processors. Eventhough the address CAM/tag arrays 1202/1206 are shown in each fragmentto be coupled with the data arrays 1207, they might be only coupled inphysical proximity of placement and layout or even by the fact that bothbelongs to a particular engine/core/processor, but there is no relationbetween addresses kept in the address arrays and the data in the dataarrays inside one fragment.

FIG. 15 shows a diagram of how loads and stores are handled byembodiments of the present invention. As depicted in FIG. 15, eachfragment is associated with its load store buffer and store retirementbuffer. For any given fragment, loads and stores that designate anaddress range associated with that fragment or another fragment are sentto that fragment's load store buffer for processing. It should be notedthat they may arrive out of order as the cores execute instructions outof order. Within each core, the core has access to not only its ownregister file but each of the other cores' register files.

Embodiments of the present invention implement a distributed load storeordering system. The system is distributed across multiple fragments.Within a fragment, local data dependency checking is performed by thatfragment. This is because the fragment only loads and stores within thestore retirement buffer of that particular fragment. This limits theneed of having to look to other fragments to maintain data coherency. Inthis manner, data dependencies within a fragment are locally enforced.

With respect to data consistency, the store dispatch gate enforces storeretirement in accordance with strict in-program order memory consistencyrules. Stores arrive out of order at the load store buffers. Loadsarrive out of order also at the load store buffers. Concurrently, theout of order loads and stores are forwarded to the store retirementbuffers for processing. It should be noted that although stores areretired in order within a given fragment, as they go to the storedispatch gate they can be out of order from the multiple fragments. Thestore dispatch gate enforces a policy that ensures that even thoughstores may reside across store retirement buffers out of order, and eventhough the buffers may forward stores to the store dispatch gate out oforder with respect to other buffers' stores, the dispatch gate ensuresthat they are forwarded to fragment memory strictly in order. This isbecause the store dispatch gate has a global view of stores retiring,and only allows stores to leave to the global visible side of the memoryin order across all the fragments, e.g., globally. In this manner, thestore dispatch gate functions as a global observer to ensure that storesultimately return to memory in order, across all fragments.

FIG. 16 shows a diagram of a store filtering algorithm in accordancewith one embodiment of the present invention. An objective of the FIG.16 embodiment is to filter the stores to prevent all stores from havingto check against all entries in the load queue.

Stores snoop the caches for address matches to maintain coherency. Ifthread/core X load reads from a cache line, it marks the portion of thecache line from which it loaded data. Upon another thread/core Y storesnooping the caches, if any such store overlaps that cache line portion,a miss-predict is caused for that load of thread/core X.

One solution for filtering these snoops is to track the load queueentries' references. In this case stores do not need to snoop the loadqueue. If the store has a match with the access mask, that load queueentry as obtained from the reference tracker will cause that load entryto miss predict.

In another solution (where there is no reference tracker), if the storehas a match with the access mask, that store address will snoop the loadqueue entries and will cause the matched load entry to miss predict.

With both solutions, once a load is reading from a cache line, it setsthe respective access mask bit. When that load retires, it resets thatbit.

FIG. 17 shows a semaphore implementation with out of order loads in amemory consistency model that constitutes loads reading from memory inorder, in accordance with one embodiment of the present invention. Asused herein, the term semaphore refers to a data construct that providesaccess control for multiple threads/cores to common resources.

In the FIG. 17 embodiment, the access mask is used to control accessesto memory resources by multiple threads/cores. The access mask functionsby tracking which words of a cache line have pending loads. An out oforder load sets the mask bit when accessing the word of the cache line,and clears the mask bit when that load retires. If a store from anotherthread/core writes to that word while the mask bit is set, it willsignal the load queue entry corresponding to that load (e.g., via thetracker) to be miss-predicted/flushed or retried with its dependentinstructions. The access mask also tracks thread/core.

In this manner, the access mask ensures the memory consistency rules arecorrectly implemented. Memory consistency rules dictates that storesupdate memory in order and loads read from memory in order for thissemaphore to work across the two cores/threads. Thus, the code executedby core 1 and core 2, where they both access the memory locations “flag”and “data”, will be executed correctly.

FIG. 18 shows an out of order loads into memory consistency model thatconstitutes loads reading for memory in order by the use of both alock-based model and a transaction-based model in accordance with oneembodiment of the present invention.

As described above, memory consistency rules dictate that stores updatememory in order and loads reefer memory in order in order that the twocores/threads communicate properly. In the bottom right-hand side ofFIG. 18 two cores are shown, core 1 and core 2. Two memory resources areused, flag and data, implement communication and share data between thecore 1 and core 2 correctly. For example, when core 1 wants to pass datato core 2, as indicated by the code within core 1 it will store the dataand then set the flag. As indicated by the code within core 2, core 2will load the flag and check whether the flag is equal to 1. If the flagis not equal to 1, core 2 will jump back and keep checking the flaguntil it does equal 1. At that point in time, it will load the data.

With an out of order architecture where loads and stores execute out oforder, a lock based memory consistency model can be used to ensure thetwo entities (e.g., core 1 and core 2) maintain in order memoryconsistency semantics. This is shown through the use of an access mask,a thread ID register, and the tracker register. The lock is set bysetting the corresponding access mask bit of any load within thecritical section of the code. If any access from another thread/core tothat cache line word happens, the lock will prevent that access. In oneembodiment, this can be implemented by treating the access as a miss.When the lock is cleared, accesses to that word are allowed.

Alternatively, a transactional-based method can be used to maintain inorder memory consistency semantics. With the transactional-based method,atomicity is set by setting the corresponding access mask bit of anyload within a transaction. If any access from another thread/core orparallel transaction to that cache line word happens while the mask bitis set it will signal the load queue entry corresponding to that load(e.g., via the tracker) to be miss-predicted/flushed or retried with itsdependent instructions. The access mask also tracks thread/core. Themask bit will be cleared when that transaction is concluded. The threadID register is used to track which thread is accessing which word of aunified store queue entry.

FIG. 19 shows a plurality of cores of a multi-core segmented memorysubsystem in accordance with one embodiment of the present invention.This embodiment shows how loads from within the multi-core segmentedmemory subsystem will be prevented from accessing a word that is markedas part of a transaction in progress (e.g., similar to a locked case).

It should be noted that if this multi-core segmented subsystem is a partof a larger cluster where there are external processors/cores/clusterswith shared memory subsystems. In this case, the load's belonging to theother external processors/cores/clusters would proceed and would not beprevented from loading from any memory location not paying attention ifthat memory location is part of a transactional access. However, allloads will mark the access mask to notify future stores that are part ofa transaction.

Snooping stores coming from other processors compare their addresses tothe mask. If a store sees the address it is trying to store to is markedin the access mask from another thread load (a load that is part of atransaction), then the store will cause that load to be miss predicted.Otherwise, the mark will be cleared upon that load retiring (e.g.,thereby completing the transaction).

FIG. 20 shows a diagram of asynchronous cores accessing a unified storequeue where stores can forward data to loads in either thread based onstore seniority in accordance with one embodiment of the presentinvention.

As described above, memory consistency rules dictates that stores updatememory in order and loads reads from memory in order so that thecores/threads communicate properly. In the bottom right-hand side ofFIG. 20 two cores are shown, core 1 and core 2. The two cores areasynchronous and execute the code indicated within each core to accessthe flag and the data memory resources.

In the FIG. 20 embodiment, the unified store queue is agnostic to any ofthe plurality of threads that may access it. In this implementation,stores from different threads can forward to loads of different threadswhile still maintaining in order memory consistency semantics byfollowing a set of algorithmic rules. Threads can forward from eachother based on store seniority.

A store is senior when all loads and stores before it in the same threadhave been executed. A thread that receives a forward from another threadcannot retire loads/stores independently. Threads have to miss predictconditionally in case other threads from which they receive forwardinghave miss predicted. A particular load can forward from the same threadforwarding store or a from a different thread senior store if there isno store forwarding to it within the same thread.

With the FIG. 20 method, atomicity is set by setting the correspondingaccess mask bit of any accesses to bytes within a word in the unifiedstore queue entry. If any access from another thread/core or paralleltransaction to that store queue entry word happens while the mask bit isset it will signal the load queue entry corresponding to that load(e.g., via the tracker) to be miss-predicted/flushed or retried with itsdependent instructions. The access mask also tracks thread/cores. Themask bit will be cleared when that transaction is concluded.

FIG. 21 shows a diagram depicting the functionality where stores haveseniority in accordance with one embodiment of the present invention. Asdepicted in FIG. 21, a particular load will forward from the same threadforwarding store. If there is no forwarding from within the thread itcan forward from a different thread senior store. This principlefunctions in a case where multiple cores/threads are accessing sharedmemory. In such cases, stores can forward from either thread to loadsfrom either thread based on store seniority, however, only if there isno forwarding from within the thread to a particular load. A store issenior when all loads and stores before it in the same thread haveexecuted.

Additionally, it should be noted that a thread cannot retireloads/stores independently. The thread has to load miss predict whenanother thread from which it received a forwarding store miss predictsor flushes.

FIG. 21 visually depicts an exemplary stream of execution between twoasynchronous cores/threads (e.g., core/thread 1 and core/thread 2). Thelines 2101-2105 show the manner in which stores forward to differentloads based on their seniority. To help illustrate how seniorityprogresses from store to store, numbers are listed next each instructionto show the different stages of execution as it progresses from 0 to 14.In particular, it should be noted the manner in which the storeindicated by the line 2103 forwards to a load within the same thread, inaccordance with the rules described above. Thus, as described above, aload that forwards from within their own thread cannot forward from anyadjacent thread. This is shown by the black crosses across theforwarding lines.

FIG. 22 shows a non-disambiguated out of order load store queueretirement implementation in accordance with one embodiment of thepresent invention (e.g., yielding low power, low die area, and lesstiming criticality) that is non-speculative.

The store retirement/reorder buffer (SRB) can operate in twoimplementations, a retirement implementation and a reorderimplementation.

In a retirement implementation, stores are loaded into the SRB from thestore queue in original program order at retirement of stores, such thatstores that are earlier in original program order are at the top of theSRB. A subsequent load can then look for address matches (e.g., usingaddress CAM), and forward from the matching entry in the SRB/storecache. In cases where there are two or more address matches, thepriority encoder can locate the correct forwarding entry by scanning forthe first one. This saves a trip to memory and allows the machine tomake forward progress. If a load is dispatched and the store thatforwards to it has already retired to the SRB/store cache, that loadforwards from the SRB/store cache and records the pairing relationshipin the prediction table. To detect the case where a load is dispatchedbefore the store that forwards to it is retired to the SRB/store cache,the load has to create an address mask where it marks its own address.This can be implemented in different ways (e.g., the FIG. 17embodiment).

As discussed above, FIG. 17 describes an access mask that functions bytracking which words of a cache line have pending loads. An out of orderload sets the mask when accessing the word of the cache line and clearsthe mask bit when that load retires. If a store from the samethread/core detects at its retirement that it writes to that word whilethe mask bit is set it will signal the load queue entry corresponding tothat load (via the tracker) to be miss-predicted/flushed or retried withits dependent instructions. The access mask also tracks thread/core.

FIG. 22 is a non-disambiguation load store queue, in the fact that itdoes not include the corresponding hardware to disambiguate out of orderloads and stores. Loads and stores dispatch out of order as machineresources allow. Traditionally, address matching and correspondingdisambiguation hardware are used in both the load queue and the storequeue to ensure correct store queue entries are forwarded to therequesting load queue entries, as described above (e.g., FIG. 5 and FIG.6). The contents of the load queue and the store queue are not visibleto outside cores/threads.

In FIG. 22, dispatched load and store addresses are not disambiguatedwith respect to entries in the store queue or the load queue. Theload/store queues are now streamlined buffer implementations withreduced die area, power consumption, and timing requirements. The SRBwill perform the disambiguation functionality. As address matches aredetected in the SRB, those matches are used to populate entries in thestore to load forwarding prediction table to enforce the forwarding asthe execution of the instruction sequence goes forward.

As loads are dispatched, they check the prediction table to see if theyare paired with a corresponding store. If the load is paired and thatparticular store has already dispatched, the load will forward from thatstore queue entry number as recorded in the prediction table. If thestore has not been dispatched yet, then the load will register its loadqueue entry number in the prediction table and will mark itself in theload queue to wait for the store data to be forwarded. When the store isdispatched later, it checks the prediction table to obtain the loadqueue entry number and forward to that load.

Once forwarding is detected for a load store pair, the PC and theaddresses of the load store pair are recorded so that the address matchis verified. If the address matches, the load will not dispatch untilthe store data is dispatched and the load will be marked to forward fromit. The prediction threshold is used to set a confidence level in theforwarding relationship between load store pairs.

FIG. 23 shows a reorder implementation of a non-disambiguated out oforder load store queue reordering implementation in accordance with oneembodiment of the present invention. FIG. 23 also yields low power, lowdie area, and less timing criticality that is non-speculative.

The store retirement/reorder buffer (SRB) can operate in twoimplementations, a retirement implementation and a reorderimplementation.

In the FIG. 23 reorder implementation, store addresses are loaded intothe SRB from the store queue out of order (e.g., as resources allow). Aseach store is allocated, it receives a sequence number. The SRB thenfunctions by reordering stores according to their sequence number suchthat they reside in the SRB in original program order. Stores that areearlier in program order are at the top of the SRB. Subsequent loadsthen look for address matches and allocation age (the program ordersequence number given at allocation time of loads and stores). As loadsare dispatched, they look to the SRB, if they see an earlier store (incomparison to their own sequence number) that has not yet dispatched (noaddress calculation yet) one of two solutions can be implemented.

1. The load does not dispatch, it waits until all earlier stores havedispatched before it dispatches itself

2. The load dispatches and marks its address in the access mask of thecache (as shown in FIG. 17). Subsequent stores check the access mask andfollow the same methodology as described in FIG. 17.

It should be noted that priority encoder functions as described above tolocate the correct forwarding entry.

FIG. 24 shows an instruction sequence (e.g., trace) reorderedspeculative execution implementation in accordance with one embodimentof the present invention. In a speculative mode, stores are moved intothe SRB from the store queue in original program order at retirement ofstores, such that stores that are earlier in original program order areat the top of the SRB. A subsequent load can then look for addressmatches (e.g., using address CAM), and forward from the matching entryin the SRB/store cache. In cases where there are two or more addressmatches, the priority encoder can locate the correct forwarding entry byscanning for the first one. This allows the machine to make forwardprogress. If a load is dispatched (the first time it checks the SRB) andthe store that forwards to it is retired to the SRB/store cache, thatload forwards from the SRB/store cache and records it pairingrelationship n the prediction table. To detect the case where a load isdispatched before the store that forwards to it is retired to theSRB/store cache, the load upon retirement will check the store queue onemore time. If the load finds a forwarding store match, it will signalthe load queue entry corresponding to that load to bemiss-predicted/flushed or retried with its dependent instructions. Theforwarding predictor will learn from this miss-forwarding.

It should be noted that the load will be able to check the SRB for amatching address against a previous store because all the stores in SRBwill not be committed to external cache/store cache architecturallyvisible state (leave the SRB storage to visible memory) till all theinstructions in the trace including the mentioned load had reached thetrace commit state (e.g., all become non speculative and trace as awhole is ready to commit).

The store retirement/reorder buffer functionally enables speculativeexecution. The results of speculative execution can be saved in thestore retirement/reorder buffer until speculative outcomes are known.The speculative results are not visible architecturally. Oncespeculative state is committed, stores can be committed to the storecache. Before committing the state, any exceptions or loads and storesthat need to be retried will signal an exception or a miss-predicts thatwill prevent the state commit. Forwarding miss-predictions betweenstores and corresponding loads can be fixed (e.g., by causing amiss-prediction that flushes the machine at the miss=forwarding loadpoint, or the like).

Additional descriptions of the SRB functionality can be found incommonly owned U.S. Publication No. 2013/0024661 by Abdallah.

FIG. 25 shows a diagram of an exemplary microprocessor pipeline 2500 inaccordance with one embodiment of the present invention. Themicroprocessor pipeline 2500 includes a fetch module 2501 thatimplements the functionality of the process for identifying andextracting the instructions comprising an execution, as described above.In the FIG. 25 embodiment, the fetch module is followed by a decodemodule 2502, an allocation module 2503, a dispatch module 2504, anexecution module 2505 and a retirement modules 2506. It should be notedthat the microprocessor pipeline 2500 is just one example of thepipeline that implements the functionality of embodiments of the presentinvention described above. One skilled in the art would recognize thatother microprocessor pipelines can be implemented that include thefunctionality of the decode module described above.

For purposes of explanation, the foregoing description refers tospecific embodiments that are not intended to be exhaustive or to limitthe current invention. Many modifications and variations are possibleconsistent with the above teachings. Embodiments were chosen anddescribed in order to best explain the principles of the invention andits practical applications, so as to enable others skilled in the art tobest utilize the invention and its various embodiments with variousmodifications as may be suited to their particular uses.

What is claimed is:
 1. A method for forwarding data from the storeinstructions to a corresponding load instruction in an out of orderprocessor, comprising: accessing an incoming sequence of instructions;reordering the incoming sequence of instructions in accordance withprocessor resources for dispatch and execution; ensuring a closestearlier store in machine order to a corresponding load by determining:if said store has an actual age but said corresponding load does nothave an actual age, then said store is earlier than said correspondingload; if said corresponding load has an actual age but said store doesnot have an actual age, then said corresponding load is earlier thansaid store; if neither said corresponding load or said store have anactual age, then a virtual identifier table is used to determine whichis earlier, wherein the virtual identifier table functions by keepingtrack of associations between store instructions and load instructionsby storing corresponding machine ID and machine resources thatcorrespond to each store instruction and a load instruction uniqueidentifier; and if both said corresponding load and said store haveactual ages, then the actual ages are used to determine which isearlier.
 2. The method of claim 1, wherein the ensuring a closestearlier store in machine order to a corresponding load maintains programsequential semantics while supporting speculative execution.
 3. Themethod of claim 1, wherein entries in the virtual identifier table allowthe store and the corresponding load to be associated with machineresources that were assigned at allocation.
 4. The method of claim 1,wherein a prediction table is used for detecting forwarding for a loadstore pair, wherein a program counter of the load store pair is recordedso that a load will wait for an address of a corresponding store in theload store pair to be dispatched and calculated prior to forwarding. 5.The method of claim 1, wherein the processor includes a load queuehaving disambiguation logic comprising a load queue entry number, astore initial age stamp, a store actual age stamp, an initial load ageand an actual load age.
 6. The method of claim 1, wherein the processorincludes a store queue having disambiguation logic comprising a storequeue entry number, a store initial age stamp, a store actual age stamp,an initial store age and an actual store age.
 7. A microprocessor,comprising: a core and a load store buffer, wherein the load storebuffer forwards data from the store instructions to a corresponding loadinstruction in an out of order processor by: accessing an incomingsequence of instructions; reordering the incoming sequence ofinstructions in accordance with processor resources for dispatch andexecution; ensuring a closest earlier store in machine order for to acorresponding load, by determining: if said store has an actual age butsaid corresponding load does not have an actual age, then said store isearlier than said corresponding load; if said corresponding load has anactual age but said store does not have an actual age, then saidcorresponding load is earlier than said store; if neither saidcorresponding load or said store have an actual age, then a virtualidentifier table is used to determine which is earlier, wherein thevirtual identifier table functions by keeping track of associationsbetween store instructions and load instructions by storingcorresponding machine ID and machine resources that correspond to eachstore instruction and a load instruction unique identifier; and if bothsaid corresponding load and said store have actual ages, then the actualages are used to determine which is earlier.
 8. The microprocessor ofclaim 7, wherein the ensuring a closest earlier store in machine orderto a corresponding load maintains program sequential semantics whilesupporting speculative execution.
 9. The microprocessor of claim 7,wherein entries in the virtual identifier table allow the store and thecorresponding load to be associated with machine resources that wereassigned at allocation.
 10. The microprocessor of claim 7, wherein aprediction table is used for detecting forwarding for a load store pair,wherein a program counter of the load store pair is recorded so that aload will wait for an address of a corresponding store in the load storepair to be dispatched and calculated prior to forwarding.
 11. Themicroprocessor of claim 7, wherein the processor includes a load queuehaving disambiguation logic comprising a load queue entry number, astore initial age stamp, a store actual age stamp, an initial load ageand an actual load age.
 12. The microprocessor of claim 7, wherein theprocessor includes a store queue having disambiguation logic comprisinga store queue entry number, a store initial age stamp, a store actualage stamp, an initial store age and an actual store age.
 13. A computersystem, comprising: a microprocessor having a core and a load storebuffer, wherein the load store buffer forwards data from the storeinstructions to a corresponding load instruction in an out of orderprocessor by: accessing an incoming sequence of instructions; reorderingthe incoming sequence of instructions in accordance with processorresources for dispatch and execution; ensuring a closest earlier storein machine order for to a corresponding load, by determining: if saidstore has an actual age but said corresponding load does not have anactual age, then said store is earlier than said corresponding load; ifsaid corresponding load has an actual age but said store does not havean actual age, then said corresponding load is earlier than said store;if neither said corresponding load or said store have an actual age,then a virtual identifier table is used to determine which is earlier,wherein the virtual identifier table functions by keeping track ofassociations between store instructions and load instructions by storingcorresponding machine ID and machine resources that correspond to eachstore instruction and a load instruction unique identifier; and if bothsaid corresponding load and said store have actual ages, then the actualages are used to determine which is earlier.
 14. The computer system ofclaim 13, wherein the ensuring a closest earlier store in machine orderto a corresponding load maintains program sequential semantics whilesupporting speculative execution.
 15. The computer system of claim 13,wherein entries in the virtual identifier table allow the store and thecorresponding load to be associated with machine resources that wereassigned at allocation.
 16. The computer system of claim 13, wherein aprediction table is used for detecting forwarding for a load store pair,wherein a program counter of the load store pair is recorded so that aload will wait for an address of a corresponding store in the load storepair to be dispatched and calculated prior to forwarding.
 17. Thecomputer system of claim 13, wherein the processor includes a load queuehaving disambiguation logic comprising a load queue entry number, astore initial age stamp, a store actual age stamp, an initial load ageand an actual load age.
 18. The computer system of claim 13, wherein theprocessor includes a store queue having disambiguation logic comprisinga store queue entry number, a store initial age stamp, a store actualage stamp, an initial store age and an actual store age.